/*
 * tmr.h
 *
 * Created: 6/13/2013 3:27:52 PM
 *  Author: Tim
 */ 


#ifndef TMR_H_
#define TMR_H_



typedef enum
{
	//dac waveform update
	dacWf0_src			=	0x10,
	dacWf1_src			=	0x11,
	
	//adc update
	adcCh0_src			=	0x20,
	adcCh1_src			=	0x21,
	adcCh2_src			=	0x22,
	adcCh3_src			=	0x23,
	
	//encoder update
	encoder0_src		=	0x30,
	encoder1_src		=	0x31,
	
	//pinChange
	pinChangeD0_src		=	0x40,
	pinChangeD1_src		=	0x41,
	pinChangeD2_src		=	0x42,
	pinChangeD3_src		=	0x43,
	pinChangeD4_src		=	0x44,
	pinChangeD5_src		=	0x45,
	pinChangeD6_src		=	0x46,
	pinChangeD7_src		=	0x47,
	pinChangeD8_src		=	0x48,
	pinChangeD9_src		=	0x49,
	pinChangeD10_src	=	0x4A,
	pinChangeD11_src	=	0x4B,
	pinChangeD12_src	=	0x4C,
	pinChangeD13_src	=	0x4D,
	
	//dio update
	dioUpdate_src		=	0x50
	
}tmrSource_t;

typedef enum
{
	//dac waveform update
	dacWf_src_msk		=	0x10,
	
	//adc update
	adcCh_src_msk		=	0x20,
	
	//encoder update
	encoder_src_msk		=	0x30,
	
	//pinChange
	pinChange_src_msk	=	0x40
	
}tmrSourceMask_t;


//use to gain access to status type
#include "../../packets/status.h"

//for access to allocations
#include "../allocations.h"

#include "../dio/dio.h"

//check to see if there is a free timer
//if so the next in line free timer will be indicated by the function return
tmrAlloc_t tmrCheckAvailability();

tmrAlloc_t tmrCheckFrequency(uint16_t freq);

//returns the number of unused timers
uint8_t tmrNumAvailabile();

//timer interrupt
status_t tmrSetupFreq(tmrAlloc_t tmrMask, uint32_t freq);

//timer interrupt handler for timers
void timerInterruptHandler(TC0_t *tmr,tmrAlloc_t selTmr);

#endif /* TMR_H_ */